package com.cssw.fyzb.wap.service;

import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.vo.*;
import com.ydn.appserver.MinaAppClient;
import com.ydn.appserver.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wondream
 */
@Service
public class AnchorService extends BaseService {

    private static final Logger logger = LoggerFactory.getLogger(UserService.class);

    @Autowired
    private MinaAppClient busiClient;

    /**
     * 通过用户id获取主播信息
     *
     * @return
     */
    public AjaxData queryAnchorByUserId(Long userId) {
        Request request = new Request("QueryAnchorByUserId");
        request.setParameter("userId", userId);
        return convertData(busiClient.send(request), AnchorVo.class);
    }

    /**
     * 通过主播id获取主播信息
     *
     * @return
     */
    public AjaxData queryAnchorById(Long anchorId) {
        Request request = new Request("QueryAnchorById");
        request.setParameter("anchorId", anchorId);
        return convertData(busiClient.send(request), UserInfoVo.class);
    }

    /**
     * 加入黑名单
     *
     * @return
     */
    public AjaxData addAnchorBlacklist(Long anchorId, Long userId) {
        Request request = new Request("AddAnchorBlacklist");
        request.setParameter("anchorId", anchorId);
        request.setParameter("userId", userId);
        return convertData(busiClient.send(request));
    }

    /**
     * 增加管理员
     *
     * @return
     */
    public AjaxData addAnchorManage(Long anchorId, Long userId) {
        Request request = new Request("AddAnchorManage");
        request.setParameter("anchorId", anchorId);
        request.setParameter("userId", userId);
        return convertData(busiClient.send(request));
    }

    /**
     * 增加敏感词
     *
     * @return
     */
    public AjaxData addAnchorSensitive(Long anchorId, String keyWord) {
        Request request = new Request("AddAnchorSensitive");
        request.setParameter("anchorId", anchorId);
        request.setParameter("keyWord", keyWord);
        return convertData(busiClient.send(request));
    }

    /**
     * 删除黑名单
     *
     * @return
     */
    public AjaxData removeAnchorBlacklist(Long id) {
        Request request = new Request("RemoveAnchorBlacklist");
        request.setParameter("id", id);
        return convertData(busiClient.send(request));
    }

    /**
     * 删除管理员
     *
     * @return
     */
    public AjaxData removeAnchorManage(Long id) {
        Request request = new Request("RemoveAnchorManage");
        request.setParameter("id", id);
        return convertData(busiClient.send(request));
    }

    /**
     * 删除敏感词
     *
     * @return
     */
    public AjaxData removeAnchorSensitive(Long id) {
        Request request = new Request("RemoveAnchorSensitive");
        request.setParameter("id", id);
        return convertData(busiClient.send(request));
    }

    /**
     * 获取黑名单列表
     *
     * @return
     */
    public AjaxPage listAnchorBlacklist(Long anchorId, int pageNumber, int pageSize) {
        Request request = new Request("ListAnchorBlacklist");
        request.setParameter("anchorId", anchorId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), AnchorBlacklistVo.class);
    }

    /**
     * 获取管理员列表
     *
     * @return
     */
    public AjaxPage listAnchorManage(Long anchorId, int pageNumber, int pageSize) {
        Request request = new Request("ListAnchorManage");
        request.setParameter("anchorId", anchorId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), AnchorManageVo.class);
    }

    /**
     * 获取敏感词列表
     *
     * @return
     */
    public AjaxPage listAnchorSensitive(Long anchorId, int pageNumber, int pageSize) {
        Request request = new Request("ListAnchorSensitive");
        request.setParameter("anchorId", anchorId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), AnchorSensitiveVo.class);
    }

    /**
     * 查看是否有直播权限
     *
     * @return com.cssw.fyzb.base.web.domain.AjaxData
     * @Param [userId]
     **/
    public AjaxPage liveVerification(Long userId) {
        Request request = new Request("LiveVerification");
        request.setParameter("userId", userId);
        return convertPage(busiClient.send(request), OperLiveVo.class);
    }

    /**
     * 开通直播权限
     *
     * @return
     * @Param
     **/
    public AjaxData openAnchor(Long userId) {
        Request request = new Request("SaveAnchor");
        request.setParameter("userId", userId);
        return convertData(busiClient.send(request), AnchorIdVo.class);
    }

    /**
     * 开通VIP直播权限
     *
     * @return
     * @Param
     **/
    public AjaxData openVipAnchor(Long userId, String tradePwd) {
        Request request = new Request("SaveVipAnchor");
        request.setParameter("userId", userId);
        request.setParameter("tradePwd", tradePwd);
        return convertData(busiClient.send(request), AnchorIdVo.class);
    }

    /**
     * 修改直播间封面
     *
     * @return
     * @Param
     **/
    public AjaxData updateThumb(Long anchorId, String thumb) {
        Request request = new Request("UpdateThumb");
        request.setParameter("anchorId", anchorId);
        request.setParameter("thumb", thumb);
        return convertData(busiClient.send(request), AnchorIdVo.class);
    }

    /**
     * 修改直播间标题
     *
     * @return
     * @Param
     **/
    public AjaxData updateTitle(Long anchorId, String title) {
        Request request = new Request("UpdateTitle");
        request.setParameter("anchorId", anchorId);
        request.setParameter("title", title);
        return convertData(busiClient.send(request), AnchorIdVo.class);
    }
}
